[hadoop@bigdata01 bin]$ hiveserver2 --help 19/12/19 20:21:18 WARN util.NativeCodeLoader: Unable to load native-hadoop library for your platform... using builtin-java classes where applicable usage: hiveserver2 --deregister <versionNumber> Deregister all instances of given version from dynamic service discovery -H,--help Print help information --hiveconf <property=value> Use value for given property
createtable hive_map( idint, namestring, members map<string,string>, age int ) rowformatdelimitedfieldsterminatedby',' collection items terminatedby'#' mapkeysterminatedby':';
desc function extended unix_timestamp; INFO : OK +--------------------------------------------------------------------------------------------+ | tab_name | +--------------------------------------------------------------------------------------------+ | unix_timestamp(date[, pattern]) - Converts the time to a number | | Converts the specified time to number of seconds since 1970-01-01. The unix_timestamp(void) overload is deprecated, use current_timestamp. | +--------------------------------------------------------------------------------------------+
1 2 3 4 5 6 7
selectunix_timestamp('2017-09-06 10:56:56') from dual; INFO : OK +-------------+ | _c0 | +-------------+ | 1504666616 | +-------------+
1 2 3 4 5 6 7 8
selectunix_timestamp('20170201 20:12:12','yyyyMMdd HH:mm:ss') from dual;
INFO : OK +-------------+ | _c0 | +-------------+ | 1485951132 | +-------------+
将给定的unix的秒数转换成为指定的格式的日期
1 2 3 4 5 6 7 8 9 10
desc function extended from_unixtime(); 将给定的unix的秒数转换成为指定的格式的日期 +--------------------------------------------------------------------------------+ | tab_name | +--------------------------------------------------------------------------------+ | from_unixtime(unix_time, format) - returns unix_time in the specified format | | Example: | | > SELECT from_unixtime(0, 'yyyy-MM-dd HH:mm:ss') FROM src LIMIT 1; | | '1970-01-01 00:00:00' | +--------------------------------------------------------------------------------+
字符串转日期:to_date
1 2 3 4 5 6 7 8 9 10
desc function extended to_date; INFO : OK +--------------------------------------------------------------------------------+ | tab_name | +--------------------------------------------------------------------------------+ | to_date(expr) - Extracts the date part of the date or datetime expression expr | | Example: | | > SELECT to_date('2009-07-30 04:17:52') FROM src LIMIT 1; | | '2009-07-30' | +--------------------------------------------------------------------------------+
1 2 3 4 5 6 7
selectto_date('2022-12-12 12:45:12') from dual; INFO : OK +-------------+ | _c0 | +-------------+ | 2022-12-12 | +-------------+
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
年: selectyear('2012-12-22') from dual; INFO : OK +-------+ | _c0 | +-------+ | 2012 | +-------+
月: selectmonth('2022-12-12 12:45:12') from dual; INFO : OK +------+ | _c0 | +------+ | 12 | +------+ 日:day 时:hour 分:minute 秒:second
日期加减运算date_add & date_sub
1 2
date_add(start_date, num_days) - Returns the date that is num_days after start_date. date_sub(start_date, num_days) - Returns the date that is num_days before start_date.
类型转换:
1 2 3
cast(value as type) selectcast('10'asint) from dual; selectcast(current_timestampasdate) from dual;
+---------------------------------------------------------------------------------------------+ | tab_name | +---------------------------------------------------------------------------------------------+ | json_tuple(jsonStr, p1, p2, ..., pn) - like get_json_object, but it takes multiple names and return a tuple. All the input parameters and output column types are string. | +---------------------------------------------------------------------------------------------+
使用案例:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
select json_tuple(json,'movie','rate','time','userid') as (movie,rate,time,userid) from rating;
desc function extended parse_url_tuple +------------------------------------------------------------------------------------------------------------------------+ | tab_name | +------------------------------------------------------------------------------------------------------------------------+ | parse_url_tuple(url, partname1, partname2, ..., partnameN) - extracts N (N>=1) parts from a URL. | | It takes a URL and one or multiple partnames, and returns a tuple. All the input parameters and output column types are | string. | | Partname: HOST, PATH, QUERY, REF, PROTOCOL, AUTHORITY, FILE, USERINFO, QUERY:<KEY_NAME> | | Note: Partnames are case-sensitive, and should not contain unnecessary white spaces. | | Example: | | > SELECT b.* FROM src LATERAL VIEW parse_url_tuple(fullurl, 'HOST', 'PATH', 'QUERY', 'QUERY:id') b as host, path, | query, query_id LIMIT 1; | | > SELECT parse_url_tuple(a.fullurl, 'HOST', 'PATH', 'QUERY', 'REF', 'PROTOCOL', 'FILE', 'AUTHORITY', 'USERINFO', | 'QUERY:k1') as (ho, pa, qu, re, pr, fi, au, us, qk1) from src a; | +------------------------------------------------------------------------------------------------------------------------+
1 2 3 4 5 6 7 8
select parse_url_tuple("http://www.baidu.com/big/webpage?cookieid=10","HOST","PATH","QUERY") from dual;
INFO : OK +----------------+---------------+--------------+ | c0 | c1 | c2 | +----------------+---------------+--------------+ | www.baidu.com | /big/webpage | cookieid=10 | +----------------+---------------+--------------+
1 2 3 4 5 6 7 8
select parse_url_tuple("http://www.baidu.com/big/webpage?cookieid=10","HOST","PATH","QUERY","QUERY:cookieid") from dual;
desc function extended assert_true; INFO : OK +----------------------------------------------------+ | tab_name | +----------------------------------------------------+ | assert_true(condition) - Throw an exception if 'condition' is not true. | | Example: | | > SELECT assert_true(x >= 0) FROM src LIMIT 1; | | NULL | +----------------------------------------------------+
elt()函数
1 2 3 4 5 6 7 8 9 10 11
desc function extended elt;
INFO : OK +----------------------------------------------------+ | tab_name | +----------------------------------------------------+ | elt(n, str1, str2, ...) - returns the n-th string | | Example: | | > SELECT elt(1, 'face', 'book') FROM src LIMIT 1;| | 'face' | +----------------------------------------------------+
1 2 3 4 5 6 7
selectelt(2,"hello","hive","spark") from dual; INFO : OK +-------+ | _c0 | +-------+ | hive | +-------+
处理空值函数NVL
1 2 3 4 5 6 7 8 9 10 11
desc function extended nvl;
INFO : OK +----------------------------------------------------+ | tab_name | +----------------------------------------------------+ | nvl(value,default_value) - Returns default value if value is null else returns value | | Example: | | > SELECT nvl(null,'bla') FROM src LIMIT 1; | | bla | +----------------------------------------------------+